#include <iostream>
#include <stdlib.h>

using namespace std;

int NumberOf1(unsigned int n)
{
	int number = 0;
	while(n)
	{
	if(n % 10 == 1)
		number++;
	n = n/10;
	}
	return number;
}

int solution2(unsigned int n)
{
	int number = 0;
	for(int i = 1;i<=n;++i)
		number += NumberOf1(i);
	return number;
}

int solution1(unsigned int n)
{
	int t = n, l, c = 0, w = 1, flag;

	do
	{
		flag = t % 10 >= 1?1:0;
		l = t % 10;
		t /= 10;
	
		cout<<"flag: "<<flag<<" l: "<<l<<" t: "<<t<<endl;

		if(l > 1)
			c += (t+1)*w;
		else if(l == 1)
			if(t==0)
				c+=n%w + 1;
			else
				c+=(t*w+n%w+1);
		else if(l==0)
			c+=t*w;
		w *=10;

		cout<<"c: "<<c<<endl;
	}while(t);
	return c;
}

int main(int argc, char** argv)
{
	int num = atoi(argv[1]);



	/*
	while(num)
	{
		if(solution1(num) != solution2(num))
		{
			cout<<num<<endl;
			break;
		}
		num++;
	}
	*/
	cout<<"n: "<<num<<" numOf1: "<<solution1(num)<<endl;
	cout<<"n: "<<num<<" numOf1: "<<solution2(num)<<endl;
}
